// Register new events
(function( $, window, undefined ) {
    // add new event shortcuts
    $.each( ( "swipeup swipedown" ).split( " " ), function( i, name ) {
        $.fn[ name ] = function( fn ) {
            return fn ? this.bind( name, fn ) : this.trigger( name );
        };
        // jQuery < 1.8
        if ( $.attrFn ) {
            $.attrFn[ name ] = true;
        }
    });

// redefine "swipe" event
	$.event.special.swipe.handleSwipe=function( start, stop ) {
		var dt=stop.time - start.time;
		var dx=start.coords[ 0 ] - stop.coords[ 0 ];
		var dy=start.coords[ 1 ] - stop.coords[ 1 ];
		var dvx=Math.round(dx/dt*100);
		var dvy=Math.round(dy/dt*100);
		if ( dt < $.event.special.swipe.durationThreshold ) {
			if (Math.abs(dx)>$.event.special.swipe.horizontalDistanceThreshold && Math.abs(dy)<$.event.special.swipe.verticalDistanceThreshold) {
				start.origin.trigger( "swipe" ).trigger( start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight" );
			}
			if (Math.abs(dy)>$.event.special.swipe.horizontalDistanceThreshold && Math.abs(dx)<$.event.special.swipe.verticalDistanceThreshold) {
				start.origin.trigger( "swipe" ).trigger( start.coords[1] > stop.coords[ 1 ] ? "swipeup" : "swipedown" );
			}
		}
		if ( (Math.abs(dvx)>10) || (Math.abs(dvy)>10) ) { // surlódás
			stop.time=start.time+Math.round(dt*1.1);
			setTimeout(function(){$.event.special.swipe.handleSwipe(start,stop);},100);
		}
	};

    $.each({ 'swipedown': "swipe", 'swipeup': "swipe" }, function( event, sourceEvent ) {
        $.event.special[ event ] = {
            setup: function() {
                $( this ).bind( sourceEvent, $.noop );
            }
        };
    });
})( jQuery, this );
